package org.glut.cloud.authentication;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.util.concurrent.TimeUnit;

/**
 * @author linghu
 * @date 2019/7/18 0018
 * @description 环境配置启动类
 */
@SpringBootApplication
@EnableDiscoveryClient  //启用服务发现功能
public class RepairAuthenticationApplication {

    public static void main(String[] args) {
           SpringApplication.run(RepairAuthenticationApplication.class, args);
    }

    /**
     * 如果key和value都使用的StringRedisSerializer序列化器，则推荐使用StringRedisTemplate
     *
     * 配置Redis的Key和Value的序列化器
     * @param redisTemplate 从容器中获取RedisTemplate
     * @return 修改后的RedisTemple
     */
    @Bean
    public RedisTemplate redisStringTemplate(RedisTemplate<Object, Object> redisTemplate) {
        // log.info("\n configure redisStringTemplate bean \n");
        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        //缓存时 key 的序列化问题
        redisTemplate.setKeySerializer(stringRedisSerializer);
        //hash key序列化方式
        redisTemplate.setHashKeySerializer(stringRedisSerializer);

        // 如果手动将Value转换成了JSON，就不要再用JSON序列化器了。

        redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
        // redisTemplate.setValueSerializer(stringRedisSerializer);
        return redisTemplate;
    }



}
